/*   1:    */ package com.atomikos.icatch.imp;
/*   2:    */ 
/*   3:    */ import com.atomikos.icatch.HeurCommitException;
/*   4:    */ import com.atomikos.icatch.HeurMixedException;
/*   5:    */ import com.atomikos.icatch.HeurRollbackException;
/*   6:    */ import com.atomikos.icatch.HeuristicMessage;
/*   7:    */ import com.atomikos.icatch.RollbackException;
/*   8:    */ import com.atomikos.icatch.StringHeuristicMessage;
/*   9:    */ import com.atomikos.icatch.TxState;
/*  10:    */ import java.util.Enumeration;
/*  11:    */ import java.util.Hashtable;
/*  12:    */ import java.util.Stack;
/*  13:    */ import java.util.Vector;
/*  14:    */ 
/*  15:    */ class TerminationResult
/*  16:    */   extends Result
/*  17:    */ {
/*  18:    */   protected boolean analyzed_;
/*  19:    */   protected Hashtable heuristicparticipants_;
/*  20:    */   protected Hashtable possiblyIndoubts_;
/*  21:    */   
/*  22:    */   public TerminationResult(int count)
/*  23:    */   {
/*  24: 68 */     super(count);
/*  25: 69 */     this.analyzed_ = false;
/*  26: 70 */     this.heuristicparticipants_ = new Hashtable();
/*  27: 71 */     this.possiblyIndoubts_ = new Hashtable();
/*  28:    */   }
/*  29:    */   
/*  30:    */   public Hashtable getHeuristicParticipants()
/*  31:    */     throws IllegalStateException, InterruptedException
/*  32:    */   {
/*  33: 86 */     analyze();
/*  34:    */     
/*  35: 88 */     return this.heuristicparticipants_;
/*  36:    */   }
/*  37:    */   
/*  38:    */   public Hashtable getPossiblyIndoubts()
/*  39:    */     throws IllegalStateException, InterruptedException
/*  40:    */   {
/*  41:102 */     analyze();
/*  42:103 */     return this.possiblyIndoubts_;
/*  43:    */   }
/*  44:    */   
/*  45:    */   protected synchronized void analyze()
/*  46:    */     throws IllegalStateException, InterruptedException
/*  47:    */   {
/*  48:110 */     if (this.analyzed_) {
/*  49:111 */       return;
/*  50:    */     }
/*  51:113 */     boolean heurmixed = false;
/*  52:    */     
/*  53:115 */     boolean heuraborts = false;
/*  54:    */     
/*  55:117 */     boolean heurcommits = false;
/*  56:    */     
/*  57:119 */     boolean heurhazards = false;
/*  58:    */     
/*  59:121 */     boolean allOK = true;
/*  60:    */     
/*  61:123 */     boolean rolledback = false;
/*  62:    */     
/*  63:    */ 
/*  64:126 */     Stack replies = getReplies();
/*  65:127 */     Enumeration enumm = replies.elements();
/*  66:129 */     while (enumm.hasMoreElements())
/*  67:    */     {
/*  68:131 */       Reply reply = (Reply)enumm.nextElement();
/*  69:133 */       if (reply.hasFailed())
/*  70:    */       {
/*  71:135 */         allOK = false;
/*  72:136 */         Exception err = reply.getException();
/*  73:137 */         if ((err instanceof RollbackException))
/*  74:    */         {
/*  75:139 */           rolledback = true;
/*  76:    */         }
/*  77:140 */         else if ((err instanceof HeurMixedException))
/*  78:    */         {
/*  79:141 */           heurmixed = true;
/*  80:142 */           HeurMixedException hm = (HeurMixedException)err;
/*  81:143 */           addErrorMessages(hm.getHeuristicMessages());
/*  82:144 */           this.heuristicparticipants_.put(reply.getParticipant(), TxState.HEUR_MIXED);
/*  83:    */         }
/*  84:146 */         else if ((err instanceof HeurCommitException))
/*  85:    */         {
/*  86:147 */           heurcommits = true;
/*  87:148 */           HeurCommitException hc = (HeurCommitException)err;
/*  88:149 */           addErrorMessages(hc.getHeuristicMessages());
/*  89:150 */           heurmixed = (heurmixed) || (heuraborts) || (heurhazards);
/*  90:151 */           this.heuristicparticipants_.put(reply.getParticipant(), TxState.HEUR_COMMITTED);
/*  91:    */         }
/*  92:156 */         else if ((err instanceof HeurRollbackException))
/*  93:    */         {
/*  94:158 */           heuraborts = true;
/*  95:159 */           heurmixed = (heurmixed) || (heurcommits) || (heurhazards);
/*  96:160 */           HeurRollbackException hr = (HeurRollbackException)err;
/*  97:161 */           addErrorMessages(hr.getHeuristicMessages());
/*  98:162 */           this.heuristicparticipants_.put(reply.getParticipant(), TxState.HEUR_ABORTED);
/*  99:    */         }
/* 100:    */         else
/* 101:    */         {
/* 102:169 */           heurhazards = true;
/* 103:170 */           heurmixed = (heurmixed) || (heuraborts) || (heurcommits);
/* 104:171 */           HeuristicMessage heurmsg = new StringHeuristicMessage("No commit ACK from participant " + reply.getParticipant());
/* 105:    */           
/* 106:    */ 
/* 107:174 */           this.errmsgvector_.addElement(heurmsg);
/* 108:175 */           this.heuristicparticipants_.put(reply.getParticipant(), TxState.HEUR_HAZARD);
/* 109:    */           
/* 110:177 */           this.possiblyIndoubts_.put(reply.getParticipant(), TxState.HEUR_HAZARD);
/* 111:    */         }
/* 112:    */       }
/* 113:    */       else
/* 114:    */       {
/* 115:189 */         HeuristicMessage[] msgs = (HeuristicMessage[])reply.getResponse();
/* 116:191 */         if (msgs != null) {
/* 117:192 */           addMessages(msgs);
/* 118:    */         }
/* 119:    */       }
/* 120:    */     }
/* 121:200 */     if (rolledback) {
/* 122:201 */       this.result_ = 6;
/* 123:202 */     } else if ((heurmixed) || ((heuraborts) && (this.heuristicparticipants_.size() != replies.size())) || ((heurcommits) && (this.heuristicparticipants_.size() != replies.size()))) {
/* 124:206 */       this.result_ = 2;
/* 125:207 */     } else if (heurhazards) {
/* 126:212 */       this.result_ = 1;
/* 127:213 */     } else if (heuraborts) {
/* 128:214 */       this.result_ = 3;
/* 129:218 */     } else if (heurcommits) {
/* 130:222 */       this.result_ = 4;
/* 131:226 */     } else if (allOK) {
/* 132:227 */       this.result_ = 0;
/* 133:    */     }
/* 134:229 */     this.analyzed_ = true;
/* 135:    */   }
/* 136:    */ }


/* Location:           C:\myfile\mysoft\apache-maven-3.5.0-bin\apache-maven-3.5.0\myrep\com\atomikos\transactions\3.7.0\transactions-3.7.0.jar
 * Qualified Name:     com.atomikos.icatch.imp.TerminationResult
 * JD-Core Version:    0.7.0.1
 */